package com.mvvmhabit.org.utils

import com.mvvmhabit.org.http.*
import io.reactivex.ObservableTransformer
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.Deferred

/**
 * @Date: 2020/10/29 15:15
 * @Author:小妖
 * @Description: 关于Rx工具类
 */
class DeferredUtil {

    companion object {

        /**
         * 线程调度器
         */
        fun <T> schedulersTransformer(): ObservableTransformer<T, T> {
            return ObservableTransformer {
                it.subscribeOn(Schedulers.io())
                    .observeOn(AndroidScheduler.mainThread())
            }
        }

        suspend fun <T> requests(deferred: Deferred<T>): T? {
            println("结果为：${deferred.await()}")
            return deferred.await()
        }
    }
}